package com.campus.event.controller;

import com.campus.event.entity.CheckIn;
import com.campus.event.service.CheckInService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/check-ins")
@RequiredArgsConstructor
public class CheckInController {
    private final CheckInService checkInService;

    @PostMapping
    @PreAuthorize("hasRole('ORGANIZER')")
    public ResponseEntity<CheckIn> checkIn(@RequestBody CheckInRequest request) {
        return ResponseEntity.ok(
            checkInService.checkIn(request.getUserId(), request.getEventId(), request.getQrCode())
        );
    }

    @GetMapping("/{id}")
    public ResponseEntity<CheckIn> getCheckIn(@PathVariable Long id) {
        return ResponseEntity.ok(checkInService.getCheckIn(id));
    }

    @GetMapping("/user/{userId}")
    public ResponseEntity<List<CheckIn>> getUserCheckIns(@PathVariable Long userId) {
        return ResponseEntity.ok(checkInService.getUserCheckIns(userId));
    }

    @GetMapping("/event/{eventId}")
    public ResponseEntity<List<CheckIn>> getEventCheckIns(@PathVariable Long eventId) {
        return ResponseEntity.ok(checkInService.getEventCheckIns(eventId));
    }
} 